<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>密令卡管理</title>
	<link type="text/css" rel="stylesheet" href="<%=basePath%><s:property value="#session.themeStyle.mainCss" default="Skin/PM/LightBlue/main.css"/>" />
</head>
<body >
	<div style="margin-left: 8px;margin-right: 8px;border-bottom: 2px #3497cf solid;height: 24px;margin-top: 0px;line-height: 24px;">
		当前位置：系统管理&nbsp;&gt;&gt;&nbsp;密令卡管理
    </div>
    <s:form theme="simple" method="post" enctype="multipart/form-data" onsubmit="return checkForm();">
	<input type="hidden" id="rowsPage" value='<s:property value="rowsPage"/>' />
	<input type="hidden" id="page" value='<s:property value="page"/>' />
	<input type="hidden" id="msg" value='<s:property value="msg"/>' />
	<div id="tableTop" class="query" style="height: 95px;">
		<ul>
			<li class="title">
				查询条件
			</li>
		</ul>
		<div>
		<div class="queryOne">
				<label>密令卡号:</label>
				<s:textfield id="snCode" name="snCode" cssClass="inputText" cssStyle="color: #5F9EA0;font-style: italic;" onblur="changeBegin(this.id,'请输入查询内容')" onfocus="changeEnd(this.id,'请输入查询内容')"/>
			</div>
			<div class="queryOne">
				<label>使用状态:</label>
				<s:select id="isBinding" name="isBinding" list="#{-1:'全部',0:'未绑定',1:'已绑定'}" cssStyle=""/>
			</div>
			<div class="queryOne" style="width: 100px">
				<input id="queryBtn" type="submit" class="but28" name="submit" value="查询"/>
			</div>
			<!-- 控制密令登录方式 -->
			<div id="operType" class="queryOne" style="width: 100px">
				<s:if test="loginType == 1">
					<a class="but28" onclick="updateSecurity(0)" style="text-decoration: none;">停用</a>
				</s:if>
				<s:else>
					<a class="but28" onclick="updateSecurity(1)" style="text-decoration: none;">启用</a>
				</s:else>
			</div>
			<div class="queryOne">
				<input type="file" name="upload" id="upload" class="inputText" style="background-color: white;"/>
			</div>
			<div class="queryOne">
				<input type="submit" class="but28" name="submit" onclick="importKeyList();" value="导入"/>
			</div>
		</div>
	</div>
	<div class="tabBlock">
		<div class="dataGrid">
			<table id="divTable" style="overflow-y: auto;">
				<tr>
					<th nowrap="nowrap">
						密令卡号
					</th>
					<th nowrap="nowrap">
						使用状态
					</th>
				</tr>
				<s:iterator value="snInfolist" var="sn" status="status">
					<tr class="trStyle">
						<td style="width: 50%">
							<s:property value="#sn.snCode" />
						</td>
						<td style="width: 50%">
							<s:if test="#sn.isBinding == 1">
								<span style="color:green;">已绑定</span>
							</s:if>
							<s:else>
								未绑定
							</s:else>
						</td>
					</tr>
				</s:iterator>
				<tr class="trBotton">
					<td colspan="4">
						<s:if test="count > 10">
						页数：<s:property value="page" />/<s:property value="allPages" /> ｜
						总数：<s:property value="count" /> ｜ 当前页：
						<select id="selectNowpage" style="width: 40px" name="page" onChange="changePageNum(this)">
								<s:bean name="org.apache.struts2.util.Counter" id="counter">
									<s:param name="first" value="1" />
									<s:param name="last" value="allPages" />
									<s:iterator>
										<option value="<s:property/>" ${page==i?"selected" : ""}>
											<s:property />
										</option>
									</s:iterator>
								</s:bean>
							</select>
						｜ 每页数：
						<select id="selectMaxPage" style="width: 50px" name="rowsPage" onChange="modPageSize(this)">
								<option value="10">
									10
								</option>
								<option value="20">
									20
								</option>
								<option value="50">
									50
								</option>
								<option value="100">
									100
								</option>
							</select>
							<s:if test="page > 1">
								<a href="javascript:upDown(1)">&lt;&lt;</a>
								<a href="javascript:upDown(${page - 1})">上页</a>
							</s:if>
							<s:if test="page < allPages">
								<a href="javascript:upDown(${page+1})">下页</a>
								<a href="javascript:upDown(${allPages})">&gt;&gt;</a>
							</s:if>
						</s:if>
					</td>
				</tr>
			</table>
		</div>
	</div>
    </s:form>
	<script type="text/javascript" src="<%=basePath%>js/jquery.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/store.js"></script>
	<script type="text/javascript">
		String.prototype.endWith=function(s){
			if(s==null||s==""||this.length==0||s.length>this.length)
				return false;
			
			if(this.substring(this.length-s.length)==s)
				return true;
			else
				return false;
			
			return true;
		}

		String.prototype.startWith=function(s){
			if(s==null||s==""||this.length==0||s.length>this.length) return false;
			
			if(this.substr(0,s.length)==s)
				return true;
			else
				return false;
			
			return true;
		}
		
		$(document).ready(function() {
			$("#selectMaxPage").val($("#rowsPage").val());
			$("#selectNowpage").val($("#page").val());
			if($("#snCode").val() == 0){
				$("#snCode").val("请输入查询内容");
			}
			if($("#binding").val() != -1){
				$("#isBinding").val($("#binding").val());
			}
			var msg = $("#msg").val();
			if(msg == "1"){
				alert("成功导入密令卡信息！");
			}else if(msg == "-1"){
				alert("没有找到导入的文件！");
			}else if(msg == "-2"){
				alert("导入密令卡信息失败！");
			}
		});
		
		/* 改变每页显示条数时，需要自动跳转到第一页 */
		function modPageSize(obj) {
			var size = $(obj).val();
			$("#rowsPage").val(size);
			getData();
		}
		
		/* 翻页时同时修改select控件页面数 */
		function upDown(n) {
			$("#selectNowpage").val(n);
			getData();
		}
		
		function changePageNum(obj) {
			var page = $(obj).val();
			$("#page").val(page);
			getData();
		}
		
		function getData(){
			$("#queryBtn").click();
		}
		
		function changeBegin(cs_id,value){ 
			var str_text = document.getElementById(cs_id);
				if (str_text.value==""){
					str_text.value=value;
				}
		}
		
		function changeEnd(cs_id,value){ 
			var str_text = document.getElementById(cs_id);
			if (str_text.value==value){
				str_text.value="";
			}
		}
		
		//系统密令登录方式控制 
		function updateSecurity(type){		
			if(confirm("确定要修改系统登录方式？")){

				$.ajax({
					url: "../sys/sysConfig-updateConfig.action",
					type:'POST',
					data: {"sysConfigs[0].name": "loginType","sysConfigs[0].value": type},
					dataType:"json",
					success: function(result){
						if(result.success){
							if(type == 1){
				 				alert("成功启用密令登录方式！");
				 				$("#operType").html("<a class=\"but28\" onclick=\"updateSecurity(0)\" style=\"text-decoration: none;\">停用</a>");
							}else{
								alert("停用密令登录，使用系统密码登录！");
								$("#operType").html("<a class=\"but28\" onclick=\"updateSecurity(1)\" style=\"text-decoration: none;\">启用</a>");
					 		}
						}else{
							alert("操作失败："+result.errorMessage);
						}
					}
				});
			}
		}
		
		function checkForm(){
			var checkResult;
			
			if($("form")[0].action.endWith("uploadSnCode.action")){
				var upload = $("#upload").val();
				if(upload == ""){
					alert("请选择要导入的文件！");
					checkResult = false
				}else if(upload.substring(upload.lastIndexOf("."), upload.length) != ".smd"){
					alert("请选择要后缀为.smd的文件！");
					checkResult = false;
				}else{
					checkResult = true;
				}
			}else{
				checkResult = true;
			}
			
			if(checkResult){
				var snCode =$.trim($("#snCode").val());
				if (snCode=="请输入查询内容"){
					snCode=""
					$("#snCode").val("");
				}else{
					$("#snCode").val(snCode);
				}
				if(snCode != ""){
					var reg = new RegExp("^[1-9][0-9]{0,9}$");
					if(!reg.test(snCode)){
						alert("请输入正确格式的密令卡号!");
						checkResult = false;
					}
				}
			}
			
			if(!checkResult){
				$("form")[0].action = "dynamicCipherCard-manage.action";
			}
			
			return checkResult;
		}
		
		// 导入密令列表
		function importKeyList(){
			$("form")[0].action = "uploadSnCode.action";
		}
		
	</script>
</body>
</html>